package com.dks.controller;


import com.dks.models.Student;
import com.dks.repository.IStudentRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("student")
@RestController
public class StudentController {

    private IStudentRepository studentRepository;

    @Autowired
    public StudentController(final IStudentRepository studentRepositoryIn) {
        this.studentRepository = studentRepositoryIn;
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取宝宝列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-student-list")
    public ResultModel<Object> getStudentList(Integer parentId, Integer pageNum, Integer pageSize) {
        if (null == parentId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "taskId");
        }
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return studentRepository.getStudentList(parentId, pageNum, pageSize);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取同班同学列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: studentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-class-student-list")
    public ResultModel<Object> getclassStudentList(Integer classId, Integer pageNum, Integer pageSize) {
        if (null == classId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "classId");
        }
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return studentRepository.getclassStudentList(classId, pageNum, pageSize);
    }

    /**
     * @Author: Ah Nan
     * @Description: 我的课表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: studentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-my-class-list")
    public ResultModel<Object> getMyClassList(String beginTime, String endTime, String courseCategory, String appointmentType, String classAttendStatus, Long studentId, Long parentId, Integer pageNum, Integer pageSize) {
        if (null == studentId && null == parentId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "studentId | parentId");
        }
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return studentRepository.getMyClassList(beginTime, endTime, courseCategory, appointmentType, classAttendStatus, studentId, parentId, pageNum, pageSize);
    }


    /**
     * @Author: Ah Nan
     * @Description: 我的课表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: studentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-my-class-detail/{studentClassId}")
    public ResultModel<Object> getMyClassList(@PathVariable(value = "studentClassId") Long studentClassId) {
        if (null == studentClassId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "studentClassId");
        }
        return studentRepository.getMyClassDetail(studentClassId);
    }


    /**
     * @Author: Ah Nan
     * @Description: 获取宝宝详情
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-student-Info")
    public ResultModel<Object> getStudentInfo(Integer id) {
        if (null == id) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "id");
        }
        return studentRepository.getStudentInfo(id);
    }

    /**
     * @Author: Ah Nan
     * @Description: 创建宝宝
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("insert-student-Info")
    public ResultModel<Object> insertStudentInfo(@RequestBody Student student) {

        if (null == student.getParentId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "ParentId");
        }

        if (student.getName() == null || student.getName().isEmpty()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "name");
        }

        if (student.getInfantName() == null || student.getInfantName().isEmpty()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "InfantName");
        }

        if (student.getProfilePhotoUrl() == null || student.getProfilePhotoUrl().isEmpty()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "ProfilePhotoUrl");
        }

        if (null == student.getSex()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "Sex");
        }

        if (student.getRelationShip() == null || student.getRelationShip().isEmpty()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "RelationShip");
        }
        if (student.getBirthdayStr() == null || student.getBirthdayStr().isEmpty()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "BirthdaysStr");
        }

        return studentRepository.insertStudentInfo(student);
    }


    /**
     * @Author: Ah Nan
     * @Description: 编辑宝宝
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("update-student-Info")
    public ResultModel<Object> updateStudentInfo(@RequestBody Student student) {

        if (null == student.getId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "studentid");
        }
//        if (null == student.getParentId()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "ParentId");
//        }

//        if (student.getName() == null || student.getName().isEmpty()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "name");
//        }
//
//        if (student.getInfantName() == null || student.getInfantName().isEmpty()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "InfantName");
//        }
//
//        if (student.getProfilePhotoUrl() == null || student.getProfilePhotoUrl().isEmpty()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "ProfilePhotoUrl");
//        }
//
//        if (null == student.getSex()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "Sex");
//        }
//
//        if (student.getRelationShip() == null || student.getRelationShip().isEmpty()) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "RelationShip");
//        }
//        if (student.getBirthdayStr() == null ) {
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "BirthdayStr");
//        }

        return studentRepository.updateStudentInfo(student);
    }

    /**
     * @Author: Ah Nan
     * @Description: 删除宝宝
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("delete-student")
    public ResultModel<Object> deleteStudent(@RequestBody Student student) {

        if (null == student.getId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "studentid");
        }


        return studentRepository.deleteStudent(student);
    }

}
